#!/bin/bash

## nodejs版本：18.18.0
##  安装目录 ：/usr/local/node-v18.18.0

if grep -q -E -i "debian" /etc/issue; then
        release="debian"
elif grep -q -E -i "ubuntu" /etc/issue; then
        release="ubuntu"
elif grep -q -E -i "centos|red hat|redhat" /etc/issue; then
        echo "没写centos系统的"
	read -p "回车退出" Enter
	exit
fi


case $(arch) in
	x86_64)  arch="x64";;
	aarch64) arch="arm64";;
	*)
		read -p "$(echo -e "暂不支持armv71,s390x等架构\n回车退出")" Enter
		exit;;
esac

echo -n '必要更新中...[apt-get update]'
apt-get update > /dev/null 2>&1
echo '	更新完成'

echo -n '必要安装中...[apt-get install wget tar -y]'
which wget > /dev/null 2>&1
if [ $? != 0 ]
then
	apt-get install wget tar -y  > /dev/null 2>&1
fi
echo '	安装完成'

echo -n '安装node...[download node-v18.18.0]'
which node > /dev/null 2>&1
if [ $? != 0 ]
then
	wget -P /root/software https://repo.huaweicloud.com/nodejs/v18.18.0/node-v18.18.0-linux-${arch}.tar.gz > /dev/null 2>&1
	mkdir -p /usr/local/node-v18.18.0
	tar -xf /root/software/node-v18.18.0-linux-${arch}.tar.gz --strip-components 1 -C /usr/local/node-v18.18.0 > /dev/null 2>&1
	echo -e '#node v18.18.0\nexport PATH=/usr/local/node-v18.18.0/bin:$PATH' > /etc/profile.d/node.sh
	source /etc/profile
	rm -rf /root/software/node-v18.18.0-linux-${arch}.tar.gz
fi
echo '	安装完成'
